package org.dtrd.modules.evaluation.entity.bean;

import cn.hutool.core.util.NumberUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.dtrd.modules.evaluation.constant.Evaluation;
import org.dtrd.modules.evaluation.entity.po.DtrdEntEvaluationRdSdsca;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: QR
 * @Date: 2021/9/26-15:01
 */
@ApiModel("Sdsca 量表信息")
@Data
public class SdscaInfo {

    private Integer dataId;

    private Integer patientId;

    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty(value = "答案", notes = "如果某个值为 -1 则表示那个选项没填")
    private List<Integer> answers;

    @ApiModelProperty("总分")
    private Float scoreTotal;

    @ApiModelProperty("饮食得分")
    private Float scoreDiet;

    @ApiModelProperty("运动得分")
    private Float scoreExercise;

    @ApiModelProperty("用药得分")
    private Float scoreMedication;

    @ApiModelProperty("血糖监控得分")
    private Float scoreMonitoring;

    @ApiModelProperty("足部检查得分")
    private Float scoreFootcheck;

    @ApiModelProperty("输出结果")
    private String output;

    public SdscaInfo parseFromPo(DtrdEntEvaluationRdSdsca po){
        this.setDataId(po.getDataId());
        this.setPatientId(po.getPatientId());
        this.setCreateTime(po.getCreateTime());
        if (po.getScoreTotal() != null) {
            this.setScoreTotal(NumberUtil.round(po.getScoreTotal().doubleValue(), 1).floatValue());
        }
        this.setScoreDiet(po.getScoreDiet());
        this.setScoreExercise(po.getScoreExercise());
        this.setScoreExercise(po.getScoreExercise());
        this.setScoreMedication(po.getScoreMedication());
        this.setScoreMonitoring(po.getScoreMonitoring());
        this.setScoreFootcheck(po.getScoreFootcheck());
        this.setOutput(po.getOutput());
        String answerString = po.getInput();
        List<Integer> answerList = new ArrayList<>(Evaluation.ProblemNum.SDSCA.getNum());
        String[] strings = answerString.split(",");
        for (String s : strings) {
            Integer answer = Integer.parseInt(s);
            answerList.add(answer);
        }
        this.setAnswers(answerList);
        return this;
    }
}
